package cn.homework.transactionMessge;


import org.apache.rocketmq.client.producer.TransactionMQProducer;
import org.apache.rocketmq.client.producer.TransactionSendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

public class TransactionProducer {


    public static void main(String[] args) throws Exception {
        // 实例化事务消息生产者Producer
        TransactionMQProducer mqProducer = new TransactionMQProducer("Transaction-producer");
        //配置路由
        mqProducer.setNamesrvAddr("127.0.0.1:9876");
        // 设置监听器
        mqProducer.setTransactionListener(new MyTransactionListener());
        // 启动生产者
        mqProducer.start();
        // 设置消息
        Message message = new Message("Transaction-message", "top-01", "我是事务消息".getBytes(StandardCharsets.UTF_8));
        // 事务消息推送
        TransactionSendResult jjk = mqProducer.sendMessageInTransaction(message, "我是事务消息");
        // 关闭生产者
        mqProducer.shutdown();



    }
}

